package com.ly.test.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

import java.lang.reflect.Method;
import java.net.InetAddress;

/**
* @author liuyi
* @date 2017/01/16 17:28
*/
public class MyAopAspect {

    private final Logger logger = LoggerFactory.getLogger(MyAopAspect.class);

    public Object handleAop(ProceedingJoinPoint pjp) throws Throwable {
        MethodSignature methodSignature = (MethodSignature)pjp.getSignature();
        Method method = methodSignature.getMethod();
        MDC.put("ip", InetAddress.getLocalHost().getHostAddress());
        logger.info("-------------------" + method);
        MDC.remove("ip");
//        logger.info();
        Object o = pjp.proceed();
//        logger.info("+++++++++++++++++++");
        return o;
    }
}
